package so.go4.snake.view;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

import so.go4.snake.entities.Food;
import so.go4.snake.entities.Ground;
import so.go4.snake.entities.Snake;
import so.go4.snake.util.Global;

public class GamePanel extends JPanel{
	
	private Snake snake;
	private Food food;
	private Ground ground;
	
	public void display(Snake snake, Food food, Ground ground){
		System.out.println("GamePanel's display");
		this.snake = snake;
		this.food = food;
		this.ground = ground;
		this.repaint();
	}

	@Override
	protected void paintComponent(Graphics g) {
		//重新显示
		g.setColor(new Color(0xcfcfcf));
		g.fillRect(0, 0, Global.WIDTH*Global.CELL_SIZE,
				Global.HEIGHT*Global.CELL_SIZE);
		if(ground != null && snake != null && food != null){
			this.ground.drawMe();
			this.snake.drawMe(g);
			this.food.drawMe(g);
			}
		}
}
